﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OleDb;
using System.Data;

public partial class BatchResults : System.Web.UI.Page
{
    SQLInteract objSQL = new SQLInteract();

    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet Table = new DataSet();
        try
        {
            Table = objSQL.ReturnDataAdapter("Select * from RESULTS_TB where FlowType='" + Request["FlowType"].Trim().ToString() + "' and BatchName='" + Request["BatchName"].Trim().ToString().Substring(0, 14) + "' and UserId='" + Session["UserId"].ToString().Trim() + "' order by CONVERT(INT, SUBSTRING([TestCase],3,3))");

            if (Table.Tables.Count.ToString() == "0")
            {
                lblDisplayTest.Text = "<b>No results found for batch '" +Request["BatchName"].Trim().ToString().Substring(15) + "'</b><br/>";
                btnDownload.Visible=false;
            }
            else
            {
                lblDisplayTest.Text = "<b>Displaying results for the batch '" + Request["BatchName"].Trim().ToString().Substring(15) + "'</b><br/>";
                btnDownload.Visible=true;
            }
            gvResultsData.PageIndex = 0;
            gvResultsData.DataSource = Table;
            gvResultsData.DataBind();
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" >alert(\"Error: " + ex.Message + "\");</script>", false);
        }
        finally
        {
        }
    }
    protected void gvResultsData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[4].Text =e.Row.Cells[3].Text.Trim().ToString() == "Fail" ?  "<a href='" + e.Row.Cells[4].Text + "' target=_new>Open</a>" : "-";
            e.Row.Cells[3].Text = e.Row.Cells[3].Text.Trim().ToString() == "Fail" ? "<Font color=red><b>" + e.Row.Cells[3].Text + "</b></font>" : e.Row.Cells[3].Text;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (gvResultsData.Rows.Count > 0)
            {
                gvResultsData.AllowPaging = false;

                GridViewExportUtil.Export("ContentReport.xls", this.gvResultsData);
            }
            else
            {

            }
        }
        catch (Exception ex)
        {

        }
        finally
        {
            gvResultsData.AllowPaging = true;
            gvResultsData.DataBind();
        }
    }
}
